package route

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"tea-fermentation-service/model"
	"log"
)

func MainApi(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{
		"flag": 1,
		"msg":  "this main router",
	})
}
func GetAllResource(c *gin.Context) {
	resource := &model.Resource{}
	resources, err := resource.QueryAllResource()
	if err != nil {
		log.Fatal("query resources all faild,error:", err)

	}
	c.JSON(http.StatusOK, gin.H{
		"flag":     1,
		"msg":      "this main router",
		"dataList": resources,
	})
}

func Query(c *gin.Context) {
	resource := &model.Resource{}
	c.BindQuery(&resource)
	resources, err := resource.Query(*resource, 30, 1)
	if err != nil {
		log.Fatal("query resources all faild,error:", err)

	}
	c.JSON(http.StatusOK, gin.H{
		"flag":     1,
		"msg":      "this main router",
		"dataList": resources,
	})
}
